package com.company.controller;

import com.company.model.Company;
import com.company.model.SortType;
import com.company.model.request.CompanyQuery;
import com.company.model.result.PageResult;
import com.company.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Tu enum@foxmail.com.
 */
@Controller
public class PageController {

  @Autowired
  ICompanyService service;

  @RequestMapping("/")
  public String index(Model model) {
    CompanyQuery newQuery = new CompanyQuery();
    newQuery.setSort(SortType.NEW.sort);
    newQuery.setPageSize(10);
    PageResult<Company> newest = service.list(newQuery);
    model.addAttribute("companies", newest.getContent());
    return "index";
  }
}
